﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;
using BrokerBase.Lib.Product;

namespace BrokerBase.Lib.Product
{
    public class ProductExpander : AbstractProductExpander
    {
        private PolicyTarget pt;
        /// <summary>
        /// 保单加载完成
        /// </summary>
        /// <param name="policy"></param>
        public override void Loaded(IPolicy policy)
        {
            IPaymentPeriod bpp = policy.Owner.BasicPolicy.SelectedPaymentPeriod;

            policy.SelectedInsurancePeriod = policy.Product.InsurancePeriods.FirstOrDefault(p => p.Style==InsurancePeriodStyle.Period && p.Value== policy.Owner.BasicPolicy.InsurancePeriodLength);

            if (bpp.Style == PaymentPeriodStyle.Once)
            {
                policy.SelectedPaymentPeriod = policy.Product.PaymentPeriods.FirstOrDefault(p => p.Style == PaymentPeriodStyle.Period && p.Value == 1);
            }
            else
            {
                policy.SelectedPaymentPeriod = policy.Product.PaymentPeriods.FirstOrDefault(p => p.Style == bpp.Style && p.Value == bpp.Value);
            }
        }

        public override PolicyTarget Target
        {
            get { return PolicyTarget.Holder; }
        }
    }
}
